package com.vm.osm.business.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.vm.osm.business.dao.OsmServerProviderMapper;
import com.vm.osm.business.dto.rsp.checkPlan.RspCheckPlan;
import com.vm.osm.business.dto.rsp.checkPlan.RspCheckPlanPage;
import com.vm.osm.business.dto.rsp.customer.Customer;
import com.vm.osm.business.dto.rsp.customer.CustomerPage;
import com.vm.osm.business.entity.OsmServerProvider;
import com.vm.osm.business.service.IOsmServerProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by chenzui on 2018/2/24.
 */
@Service
public class OsmServerProviderServiceImpl implements IOsmServerProviderService{

    @Autowired
    private OsmServerProviderMapper osmServerProviderMapper;

    @Override
    public int deleteByPrimaryKey(String id) {
        return osmServerProviderMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(OsmServerProvider record) {
        return osmServerProviderMapper.insert(record);
    }

    @Override
    public int insertSelective(OsmServerProvider record) {
        return osmServerProviderMapper.insert(record);
    }

    @Override
    public OsmServerProvider selectByPrimaryKey(String id) {
        return osmServerProviderMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(OsmServerProvider record) {
        return osmServerProviderMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(OsmServerProvider record) {
        return osmServerProviderMapper.updateByPrimaryKey(record);
    }

    @Override
    public CustomerPage queryProvidersPageByCond(Integer pageNum,Integer pageSize,String keyWord) {
        CustomerPage customerPage = new CustomerPage();
        Page page = PageHelper.startPage(pageNum,pageSize,true);
        List<Customer> dataList = osmServerProviderMapper.queryProvidersByCond(keyWord);
        customerPage.setData_list(dataList);
        customerPage.setTotal_num(page.getTotal());
        customerPage.setPage_num(page.getPageNum());
        customerPage.setPage_size(page.getPageSize());
        return customerPage;
    }

    @Override
    public CustomerPage queryByPage(Integer pageNum, Integer pageSize, String companyId,String name,String location) {
        CustomerPage customerPage = new CustomerPage();
        Page page = PageHelper.startPage(pageNum,pageSize,true);
        List<Customer> dataList = osmServerProviderMapper.queryByPage(companyId,name,location);
        customerPage.setData_list(dataList);
        customerPage.setTotal_num(page.getTotal());
        customerPage.setPage_num(page.getPageNum());
        customerPage.setPage_size(page.getPageSize());
        return customerPage;
    }

    @Override
    public void handleCustomerRelationShip(String id, String enterpriseId, Integer status) {
        OsmServerProvider provider = osmServerProviderMapper.selectByPrimaryKey(id);
//        1解除关系2删除3申请为客户4恢复为客户
        switch (status){
            //己方解除
            case 1:provider.setStatus("00004");
                   provider.setUpdateTime(new Date());
                   osmServerProviderMapper.updateByPrimaryKeySelective(provider);
            case 2:osmServerProviderMapper.deleteByPrimaryKey(provider.getId());
            case 3:provider.setStatus("00005");
                provider.setUpdateTime(new Date());
                osmServerProviderMapper.updateByPrimaryKeySelective(provider);
            case 4:provider.setStatus("00002");
                provider.setUpdateTime(new Date());
                osmServerProviderMapper.updateByPrimaryKeySelective(provider);
            default:;
        }
    }

    @Override
    public List<OsmServerProvider> find(Map<String, Object> params) {
        return osmServerProviderMapper.find(params);
    }

    @Override
    public Customer queryProvidersById(String id) {
        return osmServerProviderMapper.queryProvidersById(id);
    }
}
